Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Compare two array with same fields => if value is different highlight in html table

I have two set of array as response from an API, For example the server response is

let original= [ {firstVal:'1.2'},{SecondVal:'3.2'}];

let latest= [{firstVal:'1.2'},{SecondVal:'4.2'}]

the table will display value from latest array and logic is different value should be highlighted in bold

| Col1 | Col2 |
| 1.2 | 4.2 |

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Let's say you're rendering a table. I'm assuming that's how visualizing this data would make sense.

Then you'll store your first response and store it as its and render the default table

Now when you get your latest response. You'll start comparing row and then column wise if there is difference then the rendered value should be surrounded with a tag to make it bold. Here's a rough code

Assuming a react app


function RenderRow({row, index, latest}){
  if(latest.length < index) {
     console.log("This should not be possible")
     return null
  }

  return <tr>
  {
    row.map((column, c_index) => {
      if(latest[index][c_index] === column){
         return <td>{column}</td>
      }
      return <td><b> {column} </b></td>
    })
  }
  </tr>
}


function TableBody({original, latest}) {

  return <tbody>
   {
      original.map((row, index) => 
         <RenderRow row={row} index={index} latest={latest}/>
      )
   }
  </tbody>
}

function RenderAll(){
  let original= [ {firstVal:'1.2'},{SecondVal:'3.2'}];

  let latest= [{firstVal:'1.2'},{SecondVal:'4.2'}]
  return <Table latest={latest} original={original}/>
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!